// Promise 形式的 getSetting
export const getSetting = () => {
  return new Promise((resolve,reject) => {
      wx.getSetting({
        success:(result) => {
            resolve(result);
        },
        fail:(err) => {
            reject(err);
        }
      })
  })
}

// Promise 形式的 chooseAddress
export const chooseAddress = () => {
    return new Promise((resolve,reject) => {
        wx.chooseAddress({
          success:(result) => {
              resolve(result);
          },
          fail:(err) => {
              reject(err);
          }
        })
    })
  }

  // Promise 形式的 openSetting
export const openSetting = () => {
    return new Promise((resolve,reject) => {
        wx.openSetting({
          success:(result) => {
              resolve(result);
          },
          fail:(err) => {
              reject(err);
          }
        })
    })
  }

  // Promise 形式的 getUserProfile
export const getUserProfile = () => {
  return new Promise((resolve,reject) => {
    wx.getUserProfile({
      desc: '用户登录', // 声明获取用户个人信息后的用途，后续会展示在弹窗中
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      }
  });
  })
}

// Promise 形式的 login
export const login = () => {
  return new Promise((resolve,reject) => {
    wx.login({
      timeout: 10000,
      success:(res) => {
          resolve(res);
      },
      fail:(err) => {
          reject(err);
      }
    })
  })
}

// Promise 形式的 requestPayment
export const requestPayment = (pay) => {
  return new Promise((resolve,reject) => {
    wx.requestPayment({
      ...pay,
      success (res) {
        resolve(res);
      },
      fail (err) {
        reject(err);
      }
    })
  })
}

// Promise 形式的 showToast
export const showToast = (params) => {
  return new Promise((resolve,reject) => {
    wx.showToast({
      ...params,
      success: (res) => {
        resolve(res);
      },
      fail: (res) => {
        reject(res);
      },
    })
  })
}
